package com.zhou.framework.quartz.config;

import com.zhou.util.PropertyUtil;
import com.zhou.framework.config.DbSettingConfig;
import com.zhou.framework.quartz.common.SchedulerManager;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Properties;

@Component
public class QuartzConfig {
    public static boolean enable ;
    public static String tableFix;


    @Bean("schedulerManager")
    public SchedulerManager getSchedulerManager(DbSettingConfig config) throws Exception {
        Properties p = PropertyUtil.getProperties("quartz.properties","utf-8");

        tableFix = config.getString("quartz","table-fix","qrtz_");
        enable = config.getBoolean("quartz","enable",true);
        p.put("org.quartz.jobStore.tablePrefix",tableFix);
        SchedulerManager manager;
        if (enable){
            manager = new SchedulerManager(p);
        }else{
            manager = new SchedulerManager();
        }
        return manager;
    }

}
